package com.lost.octopus.es.helper.entity.model;

import com.lost.octopus.es.helper.annotation.EsSearch;
import com.lost.octopus.es.helper.constant.EsMatchMode;
import com.lost.octopus.es.helper.constant.EsMatchType;
import com.lost.octopus.es.helper.constant.EsSearchMode;
import com.lost.octopus.es.helper.constant.SearchHelperConstant;
import com.lost.octopus.es.helper.entity.wrapper.QueryWrapper;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 查询对象
 * @author zhangbh
 **/
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor
public class FieldConfig {

    private String name;
    private Object value;
    /**
     * es字段类型 https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html
     */
    private String fieldType;
    Class<? extends QueryWrapper> queryType;
    private EsMatchType matchType;
    private EsMatchMode matchMode;
    private EsSearchMode searchMode;

    /**
     * 其他参数，放置此位置为了方便其他Wrapper对其覆盖、扩展
     * {@link EsSearch#otherParam()} 值内容
     */
    private String otherParam;

    public FieldConfig setOtherParam(String otherParam) {
        this.otherParam = otherParam;
        return this;
    }

    /**
     * 新创建对象，并重新设置otherParam防止被改变
     * @param otherParam 重置参数
     * @return 查询对象
     */
    public FieldConfig copy(String otherParam) {
        return new FieldConfig(name, value, fieldType, queryType, matchType, matchMode, searchMode, otherParam);
    }

    /**
     * 新创建对象，防止被改变
     * @return 查询对象
     */
    public FieldConfig copy() {
        return copy(this.otherParam);
    }

    public static FieldConfig empty() {
        return new FieldConfig();
    }

    public boolean isStringType() {
        return SearchHelperConstant.STRING_TYPE.contains(fieldType);
    }
    public boolean isDateType() {
        return SearchHelperConstant.DATE_TYPE.contains(fieldType);
    }
}
